package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.CartAddNew;
import com.lucky.back.pojo.dto.ProductCategoryAddNewDTO;
import com.lucky.back.pojo.vo.CartListItemVO;
import com.lucky.back.pojo.vo.ProductCategoryListItemVO;
import com.lucky.back.service.ICartService;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "10.购物车管理模块")
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    ICartService cartService;

    @ApiOperation("添加购物车")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@RequestBody CartAddNew cartAddNew){
        cartService.addNew(cartAddNew);
        return JsonResult.ok();
    }

    @ApiOperation("删除购物车")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理【删除购物车】的请求，参数：{}", id);
        cartService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("批量删除购物车")
    @ApiOperationSupport(order = 200)
    @PostMapping("/deleteByIds")
    public JsonResult<Void> deleteByIds(@RequestBody List<Long> list){
        log.debug(list.toString()+"!!!!!!!!!!!!!!!!");
        log.debug("开始处理【删除相册】的请求，参数：{}", list);
        cartService.deleteByIds(list);
        return JsonResult.ok();
    }

    @ApiOperation("查询购物车")
    @ApiOperationSupport(order = 200)
    @GetMapping("/{userid}")
    public JsonResult<List<CartListItemVO>> list(@PathVariable Long userid){
        log.debug("开始处理【查询购物车】的请求，参数：{}");
        List<CartListItemVO> list = cartService.list(userid);
        log.debug(list.toString()+"!!!!!");
        return JsonResult.ok(list);
    }

}
